package org.i0o.appliancemanager.ui.win;

import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.i0o.appliancemanager.ui.WinSuper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseWin extends JFrame implements
		WinSuper {
	Logger						log					= LoggerFactory
															.getLogger(this
																	.getClass());

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 3476544565275431223L;

	public BaseWin() {
		init();
		initStyle();
		initLayout();
		initListener();
	}

	@Override
	public boolean open() {

		beforeOpen();

		this.setVisible(true);

		afterOpen();
		return true;
	}

	@Override
	public void close() {
		beforeClose();
		setVisible(false);
		dispose();
		afterClose();

	}

	private void init() {
		super.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}

	protected abstract void initLayout();

	protected abstract void initListener();

	protected abstract void initStyle();

	/**
	 * 关闭窗体之前的操作
	 */
	protected void beforeClose() {

	}

	/**
	 * 关闭窗体之后的操作
	 */
	protected void afterClose() {

	}

	protected void beforeOpen() {
		if (this.getTitle() == "") {
			this.setTitle(DEFAULT_TITLE);
		}

		this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
	}

	protected void afterOpen() {

	}

	protected int showConfirmDialog(String text) {
		return JOptionPane.showConfirmDialog(this,
				text,
				DEFAULT_TITLE,
				JOptionPane.YES_NO_OPTION);
	}

	protected void showMessagebox(String text,
			int messageType) {
		JOptionPane.showMessageDialog(this, text, DEFAULT_TITLE, messageType);
	}

	/**
	 * 弹出错误提示
	 * 
	 * @param text
	 *            提示内容
	 */
	protected void showErrorAlart(String text) {
		showMessagebox(text, JOptionPane.ERROR_MESSAGE);
	}

}
